﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FacadeSingTowerMall;
using System.Web.Security;
using DTOSingTowerMall;

namespace WebFormSingTowerMall.PromotionsBooking
{
    public partial class PromotionBooking : System.Web.UI.Page
    {
        AvailableStores favailstores = new AvailableStores();
        MembershipUser CurrentUser;
        UserAccountFacade AcctFacade;
        IUserDetail userDetail;
        protected void Page_Load(object sender, EventArgs e)
        {
            Calendar1.Visible = false;
            Calendar2.Visible = false;

            CurrentUser = Membership.GetUser(HttpContext.Current.User.Identity.Name);
            AcctFacade = new UserAccountFacade();

            if (!IsPostBack)
            {
                userDetail = AcctFacade.GetUserDetail((Guid)CurrentUser.ProviderUserKey);
                if (userDetail != null)
                {

                    DropDownList.DataSource = favailstores.getAvailableStoresForPromotion(CurrentUser.UserName);
                    DropDownList.DataBind();
                   // fullNameTxtBx.Text = userDetail.FullName;
                   // contactNoTxtBx.Text = userDetail.ContactNo;
                }
            }
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            Calendar1.Visible = true;
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Calendar2.Visible = true;
        }

        protected void Calendar1_SelectionChanged(object sender, EventArgs e)
        {
            startDateTxtBx.Text = Calendar1.SelectedDate.ToShortDateString() + " " + Calendar1.SelectedDate.ToShortTimeString();
            Calendar1.Visible = false;
        }

        protected void Calendar2_SelectionChanged(object sender, EventArgs e)
        {
            endDateTxtBx.Text = Calendar2.SelectedDate.ToShortDateString() + " " + Calendar2.SelectedDate.ToShortTimeString();
            Calendar2.Visible = false;
        }

        protected void Submit_btn_Click(object sender, EventArgs e)
        {
            int storeId = Convert.ToInt32 (DropDownList.SelectedValue);
            //if (DropDownList.SelectedValue)
            PromotionBookingFacade bookingFacade = new PromotionBookingFacade();
            bookingFacade.fBookPromotion(storeId, startDateTxtBx.Text, endDateTxtBx.Text
                                        , promoTitleTxtBx.Text, promoDescTxtBx.Text, imgTxtBx.Text);
        }
    }
}